//
// Copyright (c) 2009 All Right Reserved
//
// vl
//
// 2018-12-01
// Contains ...
using LargoCommon.Interfaces;
using LargoCommon.Music;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
namespace LargoPanels.Editor
{
///
/// Interact logic for BaseCell - Cell prototype.
///
public class BaseCell : SeedCell //// : FrameworkElement
{
///
/// The formatted text
///
public FormattedText formattedText;
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The given master.
[JetBrains.Annotations.UsedImplicitlyAttribute]
public BaseCell(IEditorSpace givenMaster) : base() {
this.Master = givenMaster;
}
#endregion
#region Properties
///
/// Gets or sets the master.
///
///
/// The master.
///
public IEditorSpace Master { get; set; }
///
/// Gets or sets a value indicating whether this is selected.
///
///
/// true if selected; otherwise, false.
///
public bool IsSelected { get; set; }
/// Gets or sets the point.
/// The point.
public MusicalPoint Point { get; set; }
/// Gets or sets the index of the cell.
/// The index of the cell.
public int CellIndex { get; set; }
/// Gets or sets the full pathname of the text file.
/// The full pathname of the text file.
public Path TextPath { get; set; }
public CellType CellType {
get {
CellType celltype;
if (this.GetType() == typeof(GroupCell)) {
celltype = CellType.GroupCell;
}
else {
if (this.GetType() == typeof(BarCell)) {
celltype = CellType.BarCell;
}
else {
if (this.GetType() == typeof(LineCell)) {
celltype = CellType.LineCell;
}
else {
if (this.GetType() == typeof(ContentCell)) {
celltype = CellType.ContentCell;
}
else {
celltype = CellType.None;
}
}
}
}
return celltype;
}
}
#endregion
#region Draw
///
/// Draws the cell.
///
/// The drawing context.
/// if set to true [improved text].
public void DrawCell(DrawingContext drawingContext, bool improvedText) {
if (this.Width <= 0 || this.Height <= 0) {
return;
}
var point = new Point(this.Left, this.Top);
this.Rectangle = new Rect(point, new Size(this.Width, this.Height));
//// var pen = new Pen(Brushes.Black, highlight ? 3 : 1);
//// var pen = this.IsHighlighted ? new Pen(Brushes.Blue, 3.0) : new Pen(Brushes.Black, 1.0);
Pen pen;
if (this.IsHighlighted) {
pen = new Pen(Brushes.Blue, 3.0);
}
else {
pen = new Pen(Brushes.Black, 1.0);
}
pen = this.IsSelected ? new Pen(Brushes.Red, 5.0) : pen;
drawingContext.DrawRectangle(this.ContentBrush, pen, this.Rectangle);
//// Rect rect = new Rect(this.Left, this.Top, this.Width, this.Height);
//// var brush = Brushes.Yellow; var pen = new Pen(Brushes.Black, 1.0);
//// DrawingContext.DrawGlyph seems to be much faster than DrawText.
var textPoint = new Point(this.Left + SeedSize.TextMargin, this.Top);
this.formattedText = this.FormattedText();
/*
// Create the initial formatted text string.
FormattedText formattedText = new FormattedText(
testString,
CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface("Verdana"),
32,
Brushes.Black);
*/
if (this.formattedText != null) {
if (improvedText) {
this.formattedText.SetFontWeight(FontWeights.Bold);
drawingContext.DrawText(this.formattedText, textPoint);
/*
// Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
formattedText.MaxTextWidth = 300;
formattedText.MaxTextHeight = 240;
// Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
// The font size is calculated in terms of points -- not as device-independent pixels.
formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5);
// Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
//// formattedText.SetFontWeight(FontWeights.Bold, 6, 11);
// Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
formattedText.SetForegroundBrush(
new LinearGradientBrush(
Colors.Orange,
Colors.Teal,
90.0),
6, 11);
// Use an Italic font style beginning at the 28th character and continuing for 28 characters.
formattedText.SetFontStyle(FontStyles.Italic, 28, 28);
var buildGeometry = formattedText.BuildGeometry(textPoint);
if (this.TextPath == null) {
this.TextPath = new Path { Stroke = Brushes.Black, StrokeThickness = 1 }; //// Data = buildGeometry
}
this.TextPath.Data = buildGeometry;
pen = new Pen(Brushes.Black, 1.0);
drawingContext.DrawGeometry(this.ContentBrush, pen, buildGeometry);
*/
}
else {
drawingContext.DrawText(this.formattedText, textPoint);
}
}
}
#endregion
/// Gets or sets the formatted text.
/// The formatted text.
public virtual FormattedText FormattedText() {
return null;
}
/// Convert this object into a string representation.
/// A string that represents this object.
public override string ToString() {
return string.Format("{0} L{1} W{2} T{3} H{4}", this.GetType(), this.Left, this.Width, this.Top, this.Height);
}
}
}